#include <iostream>
#include <vector>
#include "vecs_io.hpp"
#include "integrate_score.hpp"
#include <omp.h>
#include <cstring>

using namespace std;
using namespace IntegrateScore;

/*
 * 输入:
 *      cluster_score_l (n_classifier * n_query * n_cluster)
 *      weight_l_l (n_classifier * n_item * n_overlap)
 *      label_l_l (n_classifier * n_item * n_overlap)
 * 输出:
 *      score_table (n_query, n_item)
 * siftsmall_10_16_nwq_4_kmeans_multiple_dot_product_
 */

int main(int argc, char **argv) {
    if (argc != 3) {
        std::cout << argv[0] << " base_fname n_classifier" << std::endl;
        exit(-1);
    }
    printf("base_fname %s\nn_classifier %s\n", argv[1], argv[2]);

    char *base_fname = argv[1];
    int n_classifier = atoi(argv[2]);

    int n_query, n_cluster, n_item, n_overlap;
    vector<float *> cluster_score_l = read_cluster_score_l(base_fname, n_classifier, n_query, n_cluster);
    vector<float *> weight_l_l = read_weight_l_l(base_fname, n_classifier, n_item, n_overlap);
    vector<int *> label_l_l = read_label_l_l(base_fname, n_classifier, n_item, n_overlap);

    vector<vector<float>> score_table(n_query);
    for (int i = 0; i < n_query; i++) {
        score_table[i].resize(n_item);
    }

#pragma omp parallel for
    for (int i = 0; i < n_query; i++) {
        dot_product(score_table[i], cluster_score_l, weight_l_l, label_l_l, n_cluster, i, n_overlap);
    }

    save_score_table(base_fname, score_table);

    return 0;
}